import java.util.HashSet;

public class Solution341 {
    public int[] intersection(int[] nums1, int[] nums2) {
        HashSet<Integer> res = new HashSet<>();
        HashSet<Integer> num = new HashSet<>();
        for (int i : nums2) {
            num.add(i);
        }
        for (int i : nums1) {
            if (num.contains(i)){
                res.add(i);
            }
        }
        int[] nums = new int[res.size()];
        int i = 0;
        for (Integer n : res) {
            nums[i++] = n;
        }
        return nums;
    }
}
